package cn.virens.web.common.ua;

import org.apache.commons.lang3.StringUtils;

public enum UserAgent {
	/** 支付宝 */
	ALIPAYCLIENT("AlipayClient", "支付宝"),
	/** 微信 */
	MICROMESSENGER("MicroMessenger", "微信"),
	/** 未知 */
	UNDEFINED("undefined", "未知");

	private String _key;
	private String _value;

	private UserAgent(String _key, String _value) {
		this._key = _key;
		this._value = _value;
	}

	public static UserAgent parse(String ua) {
		for (UserAgent tmp : values()) {
			if (tmp.eq(ua)) return tmp;
		}

		return UNDEFINED;
	}

	public boolean eq(String ua) {
		return StringUtils.contains(ua, _key);
	}

	public String toKey() {
		return _key;
	}

	public String toValue() {
		return _value;
	}

	@Override
	public String toString() {
		return _value;
	}
}
